package replica;

import org.omg.CORBA.BooleanHolder;
import org.omg.CORBA.StringHolder;

import administrator.administratorService;
import common.CommonTools;

public class AdminClient {

	private administratorService administratorService;

	private String role;
	
	public AdminClient(administratorService administratorService, String role) {
		this.administratorService = administratorService;
		this.role = role;
	}

	public String getPlayerStatus(String adminName, String adminPassword,
			String adminIPAddress) {
		
		String lresult = null;
		
		CommonTools.writeLog(role, role, "get player status started:"
				+ "adminName:" + adminName + "; adminIPAddress:"
				+ adminIPAddress, "replica");
		StringHolder status = new StringHolder();
		BooleanHolder result = new BooleanHolder();
		
		administratorService.getPlayerStatus(adminName, adminPassword,
				adminIPAddress, result, status);

		CommonTools.writeLog(role, role, "get player status succeeded:"+result.value+" "
				+ status.value, "replica");
		
		if(result.value){
			lresult = status.value ;
		}else{
			lresult = "NAA:0" ;
		}
		return lresult;
	}

	public String suspendAccount(String adminName, String adminPassword,
			String adminIPAddress, String userNameToSuspend) {

		CommonTools.writeLog(role, role, "suspend Account started:"
				+ "adminName:" + adminName + "; adminIPAddress:"
				+ adminIPAddress + " userNameToSuspend: " + userNameToSuspend,
				"replica");

		StringHolder status = new StringHolder();
		BooleanHolder result = new BooleanHolder();
		administratorService.suspendAccount(adminName, adminPassword,
				adminIPAddress, userNameToSuspend, result, status);

		CommonTools.writeLog(role, role, "suspend Account succeeded:"
				+ status.value, "replica");
		
		if (result.value) {
			return "true";
		} else {
			return "false";
		}

	}
	public String haltLocalServer(String geolocation) {

		
		CommonTools.writeLog(role, role, "haltLocalServer started: "+ geolocation,"replica");
		
		StringHolder status = new StringHolder();
		BooleanHolder result = new BooleanHolder();
		
		//administratorService.haltLocalServer(result, status);
		CommonTools.writeLog(role, role, "haltLocalServer after remote call: "+ geolocation,"replica");
		
		if (result.value) {
			return "true";
		} else {
			return "false";
		}

	}

}
